#include <REGX52.H>
#include "LCD1602.h"
#include "Timer0.h"

unsigned char Sec,Min,Hour;

void main()
{
	Timer0Init();
	LCD_Init();
	LCD_ShowString(1,1,"Clock:");
	while(1)
	{
		LCD_ShowNum(2,1,Hour,2);
		LCD_ShowChar(2,4,':');
		LCD_ShowNum(2,6,Min,2);
		LCD_ShowChar(2,9,':');
		LCD_ShowNum(2,11,Sec,2);
	}
}

void Timer0_Rountine() interrupt 1
{	
	static unsigned int T0Count = 0;
	TL0 = 0x66;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	T0Count++;	
	if (T0Count >= 1000)
	{
		T0Count = 0;
		Sec++;
		if (Sec >= 60)
		{
			Min++;
			Sec = 0;
		}
		if (Min >= 60)
		{
			Hour++;
			Min = 0;
		}
		if (Hour >= 60)
		{
			Hour = 0;
			Min = 0;
			Sec = 0;
		}
	}
}








































